//
//  GoldAgentInfoRequest.m
//  BaseProject
//
//  Created by 王洋 on 2021/3/12.
//  Copyright © 2021 王洋. All rights reserved.
//

#import "GoldAgentInfoRequest.h"

@implementation GoldAgentInfoRequest

+ (void)request_goldAgentInfoWith:(NSString *)agentId comption:(void (^)(BOOL success, BA_AgentApplyType applyType,CommonGoldAgentModel *agentModel))comption {

    CommonGoldAgentModel *agentModel = [[CommonGoldAgentModel alloc] init];
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:agentId forKey:@"recId"];
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"userId"];
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_GetRecommender];
    
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {

        if ([data isKindOfClass:[NSDictionary class]]) {
            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {
                
                NSDictionary *resultDict = [data valueForKey:@"data"];
                NSDictionary *sysRecommender = [resultDict valueForKey:@"sysRecommender"];
                //1已申请，2未申请
                NSInteger type= [[resultDict valueForKey:@"type"] integerValue];
                CommonGoldAgentModel *model = [CommonGoldAgentModel modelWithDictionary:sysRecommender];
                comption(YES,(BA_AgentApplyType)type,model);

            } else {
                comption(NO,BA_AgentApplyType_none,agentModel);
                [SVProgressHUD showErrorWithStatus:@"金牌推荐官二维码解析失败"];
                [SVProgressHUD dismiss];
            }
        }

    } FailedBlock:^(NSError * _Nonnull error) {
        comption(NO,BA_AgentApplyType_none,nil);
        [SVProgressHUD showErrorWithStatus:@"金牌推荐官二维码解析失败"];
        [SVProgressHUD dismissWithDelay:1];
    }];
}

@end
